/*
 * Copyright (C) <2009>  <Matthew Dickinson>
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package com.pulsarwebdevelopment.concordance.plugins;

import java.util.Map;

/**
 * Provides base for all plug-in's
 * @author Matthew Dickinson
 * Last updated: 2/7/2012
 */
public interface Plugin{
	enum SelectionType{
		//DisplayText,
		FileBrowser,
		TextInput,
		CheckBoxes,
		RadioButtons,
		ConcordanceList,
		Generic
	}
	
	class Argument{
		public final SelectionType selectType;
		public final Object[] selectArgs;
		public final String displayMessage;
		public final Object selectedValue;
		
		public Argument(SelectionType type, Object[] args, String message, Object selectedVal){
			this.selectType = type;
			this.selectArgs = args;
			this.displayMessage = message;
			this.selectedValue = selectedVal;
		}
      
		public Argument copy(SelectionType newType, Object[] newArgs, String newMessage, Object newSelectedVal){
			return new Argument(
					(newType != null)? newType : this.selectType,
					(newArgs != null)? newArgs : this.selectArgs,
					(newMessage != null) ? newMessage : this.displayMessage,
					(newSelectedVal != null) ? newSelectedVal : this.selectedValue
			);
		}
      
		public Argument copy(){
		  return this.copy(null, null, null, null);
		}
	}
	
	/**
	 * Indicates whether program is running as a plug-in.
	 * Used to allow a class that extends Plugin to determine whether it can call plug-in only methods
	 * @return whether or not this plugin is running as a standalone app
	 */
	//public boolean isStandalone();

	
	public boolean requiresCompiledConcordances();
	
	/**
	 * Get the list of values required by this plugin
	 * @return a map of {@link Plugin.Argument}s that show what this plugin needs
	 */
	public Map<String, Argument> getParameterList();
	
	/**
	 * Get the title of this Plugin
	 * @return Plugin's title
	 */
	public String getTitle();
	
	/**
	 * Get the description for this Plugin
	 * @return the Plugin description
	 */
	public String getDescription();
	
	/**
	 * run this Plugin with the specified values for parameters
	 * @param args a list of {@link Plugin.Argument}s that are filled out with the required values
	 */
	public void run(Map<String, Argument> args);
	
	@Deprecated
	/**
	 * Called by PluginScreen to allow plug-in's to easily generate 
	 * an options screen
	 * @param screen The screen that will give options to user
	 * @Deprecated pre-Android version of plugin
	 */
	public void plug(PluginScreen screen);
	
	@Deprecated
	/**
	 * Called by PluginScreen when the submit button is clicked
	 * @param args The values of the option fields
	 * @Deprecated pre-Android version of plugin 
	 */
	public void go(Object[] args);

}
